Repository navigation
Hold the server's id and name inline - #233
Merged
Merged
Conversation
The connection kept the server's identity as a ServerInformationObject, two std::strings, and the published slot copied it: a 43-character id outgrows both standard libraries' inline strings, and libstdc++'s also the name, so admission made 3 (libc++) or 5 (libstdc++) heap allocations for it. InlineText<N> holds bounded text in the object (IdText is now one), and the connection and the published slot keep the id and a 64-byte name in it. get_server_information() builds the public strings on the caller's thread. server/hello's name and group/update's group_name are truncated to 64 UTF-8 bytes at a character boundary, the cap the spec is adding. Admission now allocates once on both libraries: the trust note.
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Outstanding findings leave name handoff, the 64-byte limit, and long-name allocation coverage incomplete, and the integration guide lacks truncation documentation.
4 open issues
What changed in this PR
This PR stores server identity inline through connection admission and publication, reducing heap allocations while preserving the public server-information API.
Changes:
- Adds reusable bounded text storage and UTF-8-safe truncation for server and group names.
- Replaces internal identity strings with inline values and string views.
- Updates tests, lowers the admission allocation budget to one, and refreshes stack measurements without changing the default stack size.
| File | Description |
|---|---|
tools/stack_usage/README.md |
Updates protocol-task stack measurements. |
tests/test_protocol.cpp |
Tests friendly-name truncation for both fields. |
tests/test_inline_text.cpp |
Tests truncation boundaries and capacity rejection. |
tests/test_connection_lifecycle.cpp |
Checks the published server name. |
tests/test_allocations.cpp |
Lowers the admission allocation budget to one. |
tests/CMakeLists.txt |
Registers inline-text tests. |
src/record_store.h |
Declares string-view server-ID parameters. |
src/record_store.cpp |
Uses string views in server-ID helpers. |
src/protocol.cpp |
Applies bounded friendly-name parsing. |
src/protocol_messages.h |
Defines the name limit and inline name type. |
src/inline_text.h |
Adds bounded text storage and UTF-8 truncation. |
src/crypto/keys.h |
Reuses InlineText for IDs. |
src/connection.h |
Stores server identity inline. |
src/connection.cpp |
Uses inline identity during handshakes and logging. |
src/connection_manager.h |
Defines inline published identity storage. |
src/connection_manager.cpp |
Publishes inline values and builds public strings after unlocking. |
src/connection_manager_pairing.cpp |
Adapts pairing paths to inline IDs. |
src/client.cpp |
Accepts string views when queuing pairing notifications. |
src/client_dispatch.cpp |
Transfers parsed inline names to connections. |
src/admission.h |
Accepts server IDs as string views. |
include/sendspin/types.h |
Documents friendly-name truncation. |
include/sendspin/client.h |
Updates private pairing-notification signatures. |
Review effort: Balanced
The friendly-name test built its inputs from MAX_FRIENDLY_NAME_BYTES, so a cap drifting off the spec's 64 still passed; it now uses a literal 63-byte prefix. The fake server's hello name was 21 bytes, inside libc++'s inline string, so the allocation test could not see a heap copy of it on macOS; it is now 32 bytes, named FAKE_SERVER_HELLO_NAME.
7 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Removes the server-identity heap allocations between accept and admission. The connection kept the server's id and name as a
ServerInformationObject(twostd::strings), and the published slot copied it. A 43-character id is too long for either standard library's inline string storage, and under libstdc++ so is a name over 15 characters. Admission made 3 such allocations on libc++ and 5 on libstdc++ (ESP-IDF); it now makes 1 on both.Depends on Sendspin/spec#339, which caps
server/hello'snameandgroup/update'sgroup_nameat 64 bytes in UTF-8.Change
InlineText<N>(src/inline_text.h) holds bounded text inside the object;IdTextis nowInlineText<PEER_ID_SIZE>.utf8_truncate()cuts text at a character boundary.IdTextand the name as a 64-byteServerName.get_server_id()returnsconst IdText&, and the helpers that took the id as astd::stringtake astd::string_view.get_server_information()builds the publicServerInformationObjecton the caller's thread, so the public API is unchanged.read_friendly_name()truncatesserver/hello'snameandgroup/update'sgroup_nameto 64 bytes with one warning log.group_namestays astd::stringin the publicGroupUpdateObject.tools/stack_usage/README.mdis re-derived from fresh ESP32 builds:ServerHelloMessagenow holds the name inline);Tests
test_inline_text.cpp: a table of truncation cases (at the cap, before a lead byte, inside 2-, 3- and 4-byte characters, malformed continuation runs, only continuation bytes before the cut), plusInlineText::assign()refusing text over its capacity.Protocol.FriendlyNamesAreTruncatedToTheirCap: a name at the cap is kept whole, and one with a character straddling the cap is truncated before it, for both fields.JunkProbeDoesNotBlockRealServernow also checks the published name throughget_server_information(). No test checked it before, so a mutant that dropped it passed.ADMISSION_ALLOCATIONSis lowered to 1, checked under clang / libc++ and GCC 16 / libstdc++. The one left is the trust-change noteon_handshake_complete()queues.read_friendly_name(), unbounded back-off, thelen > 0guard removed (ASan out-of-bounds read), and the published name dropped.